﻿from texttable import Texttable

def create_employee_table():
    """创建员工信息表格"""
    # 员工数据
    employees = [
        {"id": 1, "name": "张三", "department": "技术部", "position": "高级工程师", "salary": 20000, "join_date": "2020-01-15"},
        {"id": 2, "name": "李四", "department": "设计部", "position": "UI设计师", "salary": 15000, "join_date": "2019-05-20"},
        {"id": 3, "name": "王五", "department": "产品部", "position": "产品经理", "salary": 18000, "join_date": "2021-03-10"},
        {"id": 4, "name": "赵六", "department": "技术部", "position": "架构师", "salary": 25000, "join_date": "2018-11-05"},
        {"id": 5, "name": "钱七", "department": "市场部", "position": "市场专员", "salary": 12000, "join_date": "2022-02-28"}
    ]
    
    # 创建表格
    table = Texttable()
    table.set_deco(Texttable.HEADER | Texttable.VLINES | Texttable.HLINES | Texttable.BORDER)
    table.set_chars(['-', '|', '+', '='])
    table.set_cols_align(["c", "l", "l", "l", "r", "c"])
    table.set_cols_valign(["m", "m", "m", "m", "m", "m"])
    table.set_cols_width([5, 10, 10, 15, 10, 12])
    
    # 添加表头
    table.add_row(["ID", "姓名", "部门", "职位", "薪资", "入职日期"])
    
    # 添加数据行
    for emp in employees:
        table.add_row([
            emp["id"],
            emp["name"],
            emp["department"],
            emp["position"],
            f"¥{emp['salary']:,}",
            emp["join_date"]
        ])
    
    return table

def create_project_table():
    """创建项目进度表格"""
    # 项目数据
    projects = [
        {"name": "电商平台升级", "manager": "张三", "progress": 75, "status": "进行中", "deadline": "2023-12-31"},
        {"name": "移动应用开发", "manager": "李四", "progress": 90, "status": "测试中", "deadline": "2023-10-15"},
        {"name": "数据分析系统", "manager": "王五", "progress": 50, "status": "进行中", "deadline": "2024-02-28"},
        {"name": "官网 redesign", "manager": "赵六", "progress": 100, "status": "已完成", "deadline": "2023-08-30"}
    ]
    
    # 创建表格
    table = Texttable()
    table.set_deco(Texttable.HEADER | Texttable.VLINES | Texttable.HLINES | Texttable.BORDER)
    table.set_cols_align(["l", "l", "c", "l", "c"])
    table.set_cols_valign(["m", "m", "m", "m", "m"])
    table.set_cols_width([20, 10, 10, 10, 12])
    
    # 添加表头
    table.add_row(["项目名称", "负责人", "进度(%)", "状态", "截止日期"])
    
    # 添加数据行
    for project in projects:
        # 根据进度设置显示样式
        progress_bar = f"[{'#' * (project['progress'] // 10)}{' ' * (10 - project['progress'] // 10)}]"
        progress_text = f"{project['progress']}% {progress_bar}"
        
        table.add_row([
            project["name"],
            project["manager"],
            progress_text,
            project["status"],
            project["deadline"]
        ])
    
    return table

def create_summary_table():
    """创建部门汇总表格"""
    # 部门数据
    departments = [
        {"name": "技术部", "employee_count": 15, "avg_salary": 18000, "total_budget": 270000},
        {"name": "设计部", "employee_count": 8, "avg_salary": 15000, "total_budget": 120000},
        {"name": "产品部", "employee_count": 5, "avg_salary": 16000, "total_budget": 80000},
        {"name": "市场部", "employee_count": 10, "avg_salary": 13000, "total_budget": 130000},
        {"name": "行政部", "employee_count": 6, "avg_salary": 12000, "total_budget": 72000}
    ]
    
    # 创建表格
    table = Texttable()
    table.set_deco(Texttable.HEADER | Texttable.VLINES | Texttable.HLINES | Texttable.BORDER)
    table.set_cols_align(["l", "c", "r", "r"])
    table.set_cols_valign(["m", "m", "m", "m"])
    table.set_cols_width([15, 10, 15, 15])
    
    # 添加表头
    table.add_row(["部门", "员工数", "平均薪资", "总预算"])
    
    # 添加数据行
    for dept in departments:
        table.add_row([
            dept["name"],
            dept["employee_count"],
            f"¥{dept['avg_salary']:,}",
            f"¥{dept['total_budget']:,}"
        ])
    
    # 添加总计行
    total_employees = sum(dept["employee_count"] for dept in departments)
    total_budget = sum(dept["total_budget"] for dept in departments)
    avg_salary = total_budget / total_employees if total_employees > 0 else 0
    
    table.add_row([
        "总计",
        total_employees,
        f"¥{avg_salary:,.2f}",
        f"¥{total_budget:,}"
    ])
    
    return table

# 主程序
if __name__ == "__main__":
    print("=" * 60)
    print("员工信息表")
    print("=" * 60)
    emp_table = create_employee_table()
    print(emp_table.draw())
    
    print("\n" + "=" * 60)
    print("项目进度表")
    print("=" * 60)
    proj_table = create_project_table()
    print(proj_table.draw())
    
    print("\n" + "=" * 60)
    print("部门汇总表")
    print("=" * 60)
    summary_table = create_summary_table()
    print(summary_table.draw())


    input()